package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/setmeal")
@Api(tags = "套餐管理")
@Slf4j
public class SetmealController {
    @Autowired
private SetmealService setmealService;

    @ApiOperation("分页查询套餐")
    @GetMapping("/page")
    public Result<PageResult> page( SetmealPageQueryDTO dto) {
        log.info("dto: {}", dto);
       PageResult pageResult = setmealService.page(dto);
       return Result.success(pageResult);
    }

    @ApiOperation("新增套餐")
    @PostMapping()
    public Result add(@RequestBody SetmealDTO setmealDTO) {
        log.info("setmealDTO: {}", setmealDTO);
        setmealService.add(setmealDTO);
        return Result.success();
    }

    @ApiOperation("起售停售套餐")
    @PostMapping("/status/{status}")
    public Result status(@PathVariable("status") Integer status, @RequestParam("id") Long id) {
        log.info("status: {}, id: {}", status, id);
       setmealService.status(status, id);
        return Result.success();
    }

    @ApiOperation("根据id查询套餐")
    @GetMapping("/{id}")
    public Result<SetmealVO> get(@PathVariable("id") Long id) {
        log.info("id: {}", id);
        SetmealVO setmealVO = setmealService.getById(id);
        return Result.success(setmealVO);
    }

    @ApiOperation("修改套餐")
    @PutMapping()
    public Result update(@RequestBody SetmealDTO setmealDTO) {
        log.info("setmealDTO: {}", setmealDTO);
        setmealService.update(setmealDTO);
        return Result.success();
    }

    @ApiOperation("批量删除套餐")
    @DeleteMapping()
    public Result delete(@RequestParam("ids") String ids) {
        log.info("ids: {}", ids);
        setmealService.delete(ids);
        return Result.success();
    }
}
